package com.homegoods.designer.ui.activity;

import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.designer.R;
import com.homegoods.designer.model.CaseDetailModel;
import com.homegoods.designer.model.DesignerCaseModel;
import com.homegoods.designer.model.DesignerHomeModel;
import com.homegoods.designer.presenter.DesignerMoreCasePresenter;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.base.KRefreshListActivity;
import com.kedll.library.databinding.GeneralIncludeActionbarAndListBinding;
import com.kedll.library.util.MyUtils;

/**
 * @author QiQi
 * @ClassName: DesignerMoreCaseActivity
 * @date 2018/9/16
 * @description 更多案例界面
 */
@Route(path = ARouterPath.PATH_MORE_CASE)
public class DesignerMoreCaseActivity extends KRefreshListActivity<GeneralIncludeActionbarAndListBinding, DesignerMoreCasePresenter> {

    @Autowired(name = "data")
    public DesignerHomeModel homeModel;

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        ARouter.getInstance().inject(this);
        setTitle("更多案例");
    }

    @Override
    protected DesignerMoreCasePresenter getPresenter() {
        return new DesignerMoreCasePresenter(this);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        appBarLayout.setBackgroundResource(R.color.color_f6f6f6);
        refreshLayout.setBackgroundResource(R.color.white);
        list.setPadding(MyUtils.dp2px(16), MyUtils.dp2px(16), MyUtils.dp2px(16), 9);
        list.setClipToPadding(false);
        refreshLayout.setClipToPadding(false);
    }


    @Override
    protected void initEvent() {
        super.initEvent();
        adapter.setOnItemClickListener((MultiTypeAdapter.OnItemClickListener<DesignerCaseModel>) (v, iItem) -> {
            DesignerCaseModel caseModel =  iItem.getData();
            CaseDetailModel detailModel = new CaseDetailModel();
            detailModel.setCaseModel(caseModel);
            detailModel.setHomeModel(homeModel);

            ARouter.getInstance()
                    .build(ARouterPath.PATH_CASE_DETAIL)
                    .withObject("data", detailModel)
                    .navigation();
        });
    }

    @Override
    protected int getLayout() {
        return R.layout.general_include_actionbar_and_list;
    }
}
